package com.tl.boot.service.user.impl;

import com.tl.boot.entity.user.domain.condition.ListUsersCondition;
import com.tl.boot.entity.user.domain.po.UserBasicInfo;
import com.tl.boot.entity.user.dto.AddUserInfoDTO;
import com.tl.boot.entity.user.dto.ListUserDTO;
import com.tl.boot.entity.user.dto.UpdateUserDTO;
import com.tl.boot.entity.user.vo.BaseInfoVO;
import com.tl.boot.entity.user.vo.UserInfoVO;
import com.tl.boot.mapper.user.UserMapper;
import com.tl.boot.service.user.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * com.tl.boot.service.user.impl -- UserServiceImpl
 * Description:
 * Created by joshua_liu <a href="mailto:joshualwork@163.com"></a>
 * On 2019/9/16 16:38
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public Long addUserBasicInfo(AddUserInfoDTO dto) {
        UserBasicInfo basicInfo = new UserBasicInfo();
        BeanUtils.copyProperties(dto,basicInfo);
        userMapper.addUserBasicInfo(basicInfo);
        return basicInfo.getUserId();
    }

    @Override
    public void updateUserBasicInfo(UpdateUserDTO dto) {
        UserBasicInfo userBasicInfo = new UserBasicInfo();
        BeanUtils.copyProperties(dto,userBasicInfo);
        userBasicInfo.setUserId(dto.getId());
        userMapper.updateUserBasicInfo(userBasicInfo);
    }

    @Override
    public List<UserInfoVO> listUsers(ListUserDTO dto) {
        ListUsersCondition condition = new ListUsersCondition();
        BeanUtils.copyProperties(dto,condition);
        return userMapper.listUsers(condition);
    }

    @Override
    public BaseInfoVO getBaseInfo(Long userId) {
        return userMapper.getBaseInfo(userId);
    }
}
